\! gs_ktool -d all
\! gs_ktool -g

DROP CLIENT MASTER KEY MyCMK CASCADE;
CREATE CLIENT MASTER KEY MyCMK WITH ( KEY_STORE = gs_ktool , KEY_PATH = "gs_ktool/1" , ALGORITHM = AES_256_CBC);
CREATE COLUMN ENCRYPTION KEY MyCEK770 WITH VALUES (CLIENT_MASTER_KEY = MyCMK, ALGORITHM = AEAD_AES_256_CBC_HMAC_SHA256);
CREATE TABLE IF NOT EXISTS tr2(i1 INT ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED) , i2 INT);
INSERT INTO tr2 (i1, i2) VALUES (12, 13);
INSERT INTO tr2 VALUES (15,16);
INSERT INTO tr2 (i1, i2) VALUES (22, 23), (24, 25), (26,27);
INSERT INTO tr2 VALUES (35,36), (36,37), (38,39);
SELECT * from tr2 ORDER BY i2;
SELECT i1 FROM tr2 WHERE i2  = 25;
SELECT i1 FROM tr2 WHERE i1  = 24;
DROP TABLE tr2;

CREATE TABLE IF NOT EXISTS tr1(i1 INT ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = DETERMINISTIC) ,i2 INT ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE =
 RANDOMIZED), i3 INT);
INSERT INTO tr1 VALUES (1, 2, 3);
select * from tr1;
DROP TABLE tr1;

 CREATE TABLE IF NOT EXISTS tr3(i1 INT ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED) ,i2 INT ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE =
 RANDOMIZED), i3 INT);
 INSERT INTO tr3 VALUES (1, 2, 3);
select * from tr3;
DROP TABLE tr3;


CREATE TABLE IF NOT EXISTS tr2(
i INT,
ii INT,
i1 INT1       ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
i2 INT2       ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
i4 INT4       ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
i8 INT8       ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
f4 FLOAT4     ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
f8 FLOAT8     ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
c  CHAR       ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
c8 CHAR(8)    ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
v  VARCHAR    ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
v8 VARCHAR(8) ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED),
b  BYTEA      ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED)
);

INSERT INTO tr2 VALUES ( 1, 1, 1, 1, 1, 1, 3.14, 3.14,'C','IDO'       ,'Ido''s'    , 'Shlomo'    , '\x1234');
BEGIN;
DECLARE select_all_tr2 CURSOR FOR SELECT * from tr2 ORDER BY i;
FETCH 5 from select_all_tr2;
CLOSE select_all_tr2;
END;
INSERT INTO tr2 VALUES (-1, -1, 0,-1,-1,-1,-3.14,-3.14,' ','AVI'       ,'Avi''s'    , 'Kessel'    , '\x5678');
BEGIN;
DECLARE select_all_tr2 CURSOR FOR SELECT * from tr2 ORDER BY i;
FETCH 5 from select_all_tr2;
CLOSE select_all_tr2;
END;
INSERT INTO tr2 VALUES ( 4, 4, 0, 0, 0, 0,-0.14,-0.14,'z','A A       ','A a       ', 'A a       ', '\xababababababababababababababababababababab');
BEGIN;
DECLARE select_all_tr2 CURSOR FOR SELECT * from tr2 ORDER BY i;
FETCH 5 from select_all_tr2;
CLOSE select_all_tr2;
END;
BEGIN;
DECLARE select_one_tr2 CURSOR FOR SELECT * from tr2 WHERE i1=1 AND ii=1;
FETCH 5 from select_one_tr2;
CLOSE select_one_tr2;
END;
DROP TABLE tr2;
CREATE TABLE products (
    product_no integer DEFAULT 1,
    name text ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED) DEFAULT 'Test Product',
    TITLE varchar(35) NOT NULL DEFAULT ' ',
   price numeric ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = MyCEK770, ENCRYPTION_TYPE = RANDOMIZED) DEFAULT 9.99,
    MAX_PRICE decimal(6,0) DEFAULT NULL
);
INSERT INTO products (name) VALUES ('Test2');
INSERT INTO products (price) VALUES (34);
INSERT INTO products (name) VALUES (DEFAULT);
INSERT INTO products (price) VALUES (DEFAULT);
INSERT INTO products (name, price) VALUES (DEFAULT, DEFAULT);
INSERT INTO products DEFAULT VALUES;

SELECT * FROM products;

DROP TABLE products;
DROP CLIENT MASTER KEY MyCMK CASCADE;

\! gs_ktool -d all